Reduce memory usage during collection deletion#2492
Open
Reduce memory usage during collection deletion#2492
Conversation
Author
|
This will need to be backported for 0.25 (AAP 2.4/2.5/2.6) and 0.28 (AAP upstream/2.7) please. |
gerrod3
requested changes
Apr 2, 2026
Contributor
gerrod3
left a comment
There was a problem hiding this comment.
set_collection_deferred_fields is a blunt instrument used to work around having to change multiple spots in our collection sync code (some of them being in pulpcore!) and as such we shouldn't overuse when trying to optimize pulp-ansible. For this case we can easily fix the issues by being smarter with the querysets we write.
gerrod3
requested changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reduce memory usage during collection deletion
Problem
Deleting collections with many versions causes worker processes to consume excessive memory and get killed with SIGKILL. This occurs because Django loads all fields (including large JSON fields) for each CollectionVersion into memory. When multiplied across many versions, this causes the worker process to be terminated.
Solution
This PR applies targeted QuerySet field selection using
.only()to load only the fields needed for deletion operations, avoiding the large JSON fields that aren't required.Changes:
pulp_ansible/app/galaxy/v3/views.py:.only("pk")when iterating collection versions and their repositories inCollectionViewSet.destroy()AnsibleRepositorylookup withfilter(pk__in=...)to prevent N+1 queries.only("namespace", "name", "version")when loading collection dependentspulp_ansible/app/tasks/deletion.py:.only("pk")when loading collection versions and iterating their repositories indelete_collection()taskBy loading only the required fields, we avoid pulling large JSON blobs (
docs_blob,metadata,dependencies, etc.) into memory when they're not needed for the deletion operation.Related Work